package com.tianhui.consignortwofei.mvp.ui.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.tianhui.consignortwofei.R;
import com.tianhui.consignortwofei.mvp.model.enty.OrderInfo;
import com.tianhui.consignortwofei.pattern.orderStatus.status.IOrderStatus;

import org.yczbj.ycrefreshviewlib.adapter.RecyclerArrayAdapter;
import org.yczbj.ycrefreshviewlib.holder.BaseViewHolder;

/**
 * @author fgs
 * @date 2020/8/27
 * @description
 **/
public class SourceDocumentListAdapter extends RecyclerArrayAdapter<OrderInfo> {
    private IOrderStatus iOrderStatus;

    public SourceDocumentListAdapter(Context context, IOrderStatus iOrderStatus) {
        super(context);
        this.iOrderStatus = iOrderStatus;
    }

    @Override
    public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
        return new InTransitListViewHolder(parent, R.layout.item_source_document_list);
    }

    private class InTransitListViewHolder extends BaseViewHolder<OrderInfo> {

//        private ImageView iv_head;
//        private TextView tv_name;
//        private TextView tv_license;
        private TextView tv_zhuangtai;
        private TextView tv_zhuang_dress_one;
        private TextView tv_zhuang_dress_two;
        private TextView tv_zhuang_xie_one;
        private TextView tv_zhuang_xie_two;
        private LinearLayout ll_driver_line_body;
        private TextView tv_yunfei;
        private TextView tv_pay_type;

        private TextView tv_guanli;
        private TextView tv_cancel;
        private TextView tv_true_shou;
        private TextView tv_true_zhuang;
        private TextView tv_xiashou_num;
        private TextView tv_huoquan_num;
        private TextView tv_weight;




        public InTransitListViewHolder(ViewGroup parent, int res) {
            super(parent, res);

//            iv_head = getView(R.id.iv_head);
//            tv_name = getView(R.id.tv_name);
//            tv_license = getView(R.id.tv_license);
            tv_zhuangtai = getView(R.id.tv_zhuangtai);
            tv_zhuang_dress_one = getView(R.id.tv_zhuang_dress_one);
            tv_zhuang_dress_two = getView(R.id.tv_zhuang_dress_two);
            tv_zhuang_xie_one = getView(R.id.tv_zhuang_xie_one);
            tv_zhuang_xie_two = getView(R.id.tv_zhuang_xie_two);
            ll_driver_line_body = getView(R.id.ll_driver_line_body);
            tv_yunfei = getView(R.id.tv_yunfei);
            tv_pay_type = getView(R.id.tv_pay_type);

            tv_guanli = getView(R.id.tv_guanli);
            tv_cancel = getView(R.id.tv_cancel);
            tv_true_shou = getView(R.id.tv_true_shou);
            tv_true_zhuang = getView(R.id.tv_true_zhuang);
            tv_xiashou_num = getView(R.id.tv_xiashou_num);
            tv_huoquan_num = getView(R.id.tv_huoquan_num);
            tv_weight = getView(R.id.tv_weight);


//            addOnClickListener(R.id.iv_phone);
            addOnClickListener(R.id.ll_driver_line_body);

            addOnClickListener(R.id.tv_guanli);
            addOnClickListener(R.id.tv_liulan);
            addOnClickListener(R.id.tv_tonghua);
            addOnClickListener(R.id.iv_zhongzhi);
            addOnClickListener(R.id.tv_zhuan);


//            addOnClickListener(R.id.tv_true_shou);
//            addOnClickListener(R.id.tv_true_zhuang);
        }

        @Override
        public void setData(OrderInfo data) {
            super.setData(data);

//            tv_name.setText(data.drivername);
//            tv_license.setText(data.vehiclenum);
            tv_zhuang_dress_one.setText(data.deliverprovince + data.delivercity + data.delivercounty + data.deliverdetails);
            tv_zhuang_dress_two.setText(data.delivercity + data.delivercounty+data.lendtime+"前");
            tv_zhuang_xie_one.setText(data.destinationprovince + data.destinationcity + data.destinationcounty + data.destinationdetails);
            tv_zhuang_xie_two.setText(data.destinationcity + data.destinationcounty);

            tv_yunfei.setText("￥"+data.totalprice);
            tv_huoquan_num.setText("货权:"+data.customername);
            tv_weight.setText("重量："+data.weight+"吨   "+data.destinationusername);

            if (null!=data.businessno&&!TextUtils.isEmpty(data.businessno)){
                tv_xiashou_num.setVisibility(View.VISIBLE);
                tv_xiashou_num.setText("销售单号："+data.businessno);
            }else {
                tv_xiashou_num.setVisibility(View.GONE);
            }

//            tv_zhuangtai.setText(data.isstatetext);


//            int orderStatusType = iOrderStatus.getFeiOrderType();
//
//            if (OrderType.TYPE_CATCH_TIME==orderStatusType){
//                tv_pay_type.setText("(待支付)");
//                tv_guanli.setVisibility(View.VISIBLE);
//                tv_cancel.setVisibility(View.VISIBLE);
//                tv_true_shou.setVisibility(View.GONE);
//                tv_true_zhuang.setVisibility(View.GONE);
//            }else if (OrderType.TYPE_ING_TIME==orderStatusType){
//                tv_pay_type.setText("(待支付)");
//                tv_guanli.setVisibility(View.VISIBLE);
//                tv_cancel.setVisibility(View.VISIBLE);
//                tv_true_shou.setVisibility(View.GONE);
//                tv_true_zhuang.setVisibility(View.GONE);
//
//            }else if (OrderType.TYPE_PAYING_TIME==orderStatusType){
//                tv_pay_type.setText("(待支付)");
//                tv_guanli.setVisibility(View.VISIBLE);
//                tv_cancel.setVisibility(View.GONE);
//                tv_true_shou.setVisibility(View.VISIBLE);
//                tv_true_zhuang.setVisibility(View.VISIBLE);
//
//            }else if (OrderType.TYPE_SUCCESS_TIME==orderStatusType){
//                tv_pay_type.setText("(已支付)");
//                tv_guanli.setVisibility(View.GONE);
//                tv_cancel.setVisibility(View.GONE);
//                tv_true_shou.setVisibility(View.GONE);
//                tv_true_zhuang.setVisibility(View.GONE);
//
//            }else if (OrderType.TYPE_CANCEL_TIME==orderStatusType){
//                tv_pay_type.setText("(待支付)");
//                tv_guanli.setVisibility(View.GONE);
//                tv_cancel.setVisibility(View.GONE);
//                tv_true_shou.setVisibility(View.GONE);
//                tv_true_zhuang.setVisibility(View.GONE);
//
//            }




//                if (iOrderStatus.getOrderStatusType() == OrderType.TYPE_PAYMENT) {
//                    freightLinearLayout.setVisibility(View.VISIBLE);
//                    if (!TextUtils.isEmpty(data.issettle) && (data.issettle.equals("0") || data.issettle.equals("3"))) {
//                        submitTextView.setVisibility(View.VISIBLE);
//                    } else {
//                        submitTextView.setVisibility(View.GONE);
//                    }
//
//                } else {
//
//                }


//            //货源单号
//            orderNumberTextView.setText("货源单号：" + data.billno);
//            //取单地
//            twoDetailItemView.setContent(data.placeprovince + data.placecity + data.placecounty + data.placedetails);
//            //装货地
//            threeDetailItemView.setContent(data.deliverprovince + data.delivercity + data.delivercounty + data.deliverdetails);
//            //目的地
//            fourDetailItemView.setContent(data.destinationprovince + data.destinationcity + data.destinationcounty + data.destinationdetails);
//            //货权
//            if (RoleController.getInstance().isShowCustomerName()) {
//                sixDetailItemView.setVisibility(View.VISIBLE);
//                sixDetailItemView.setContent(data.customername);
//                sixDetailItemView.setTitle("货权：");
//            } else {
//                sixDetailItemView.setVisibility(View.GONE);
//            }
//            //车牌号
//            if (RoleController.getInstance().isDispatchOrderShowVehicleNumber()) {
//                eightDetailItemView.setVisibility(View.VISIBLE);
//                eightDetailItemView.setContent(data.vehiclenum);
//                eightDetailItemView.setTitle("车牌号：");
//            } else {
//                eightDetailItemView.setVisibility(View.GONE);
//            }
//
//            //发单时间
//            timeDetailItemView.setContent(data.sendordertime);
//            if (iOrderStatus != null) {
//                //状态
//                if (!TextUtils.isEmpty(iOrderStatus.getOrderStatus(data))) {
//                    orderStatusTextView.setText(Html.fromHtml(iOrderStatus.getOrderStatus(data)));
//                    orderStatusTextView.setVisibility(View.VISIBLE);
//                } else {
//                    orderStatusTextView.setVisibility(View.INVISIBLE);
//                }
//                //调度单号
//                String dispatchNumber = iOrderStatus.getDispatchNumber(data);
//                if (!TextUtils.isEmpty(dispatchNumber)) {
//                    oneDetailItemView.setVisibility(View.VISIBLE);
//                    oneDetailItemView.setContent(iOrderStatus.getDispatchNumber(data));
//                } else {
//                    oneDetailItemView.setVisibility(View.GONE);
//                }
//                //运费总计
//                String freight = iOrderStatus.getFreight(data);
//                freightTextView.setText(freight);
//                if (iOrderStatus.getOrderStatusType() == OrderType.TYPE_PAYMENT) {
//                    freightLinearLayout.setVisibility(View.VISIBLE);
//                    if (!TextUtils.isEmpty(data.issettle) && (data.issettle.equals("0") || data.issettle.equals("3"))) {
//                        submitTextView.setVisibility(View.VISIBLE);
//                    } else {
//                        submitTextView.setVisibility(View.GONE);
//                    }
//
//                } else {
//                    submitTextView.setVisibility(View.GONE);
//                    freightLinearLayout.setVisibility(View.GONE);
//                }
//
//
//                //货源单
//                if (iOrderStatus.getOrderStatusType() == OrderType.TYPE_SOURCE
//                        ||iOrderStatus.getOrderStatusType() == OrderType.TYPE_SOURCE_DINGJIN) {
//                    //分享码
//                    shareCodeTextView.setVisibility(View.VISIBLE);
////                    //编辑
////                    editOrderTextView.setVisibility(View.VISIBLE);
//                    //货物明细
//                    goodsDetailLinearLayout.setVisibility(View.VISIBLE);
//                    goodsWeightTextView.setText("总重：" + data.weight + "吨");
//                    if (!TextUtils.isEmpty(data.detachable) && data.detachable.equals("1")) {
//                        String grabWeight = "0";
//                        if (!TextUtils.isEmpty(data.weight) && !TextUtils.isEmpty(data.leftweight)) {
//                            grabWeight = new BigDecimal(data.weight).subtract(new BigDecimal(data.leftweight)).toString();
//                        }
//                        grabWeightTextView.setText("已抢：" + grabWeight + "吨");
//                        grabWeightTextView.setVisibility(View.VISIBLE);
//                    } else {
//                        grabWeightTextView.setVisibility(View.GONE);
//                    }
//                    priceTextView.setText("单价：" + data.baseprice + "元/吨");
//
//                    //指定承运人
//                    if (!TextUtils.isEmpty(data.sentto) && data.sentto.equals("02") && !TextUtils.isEmpty(data.senttodetails)) {
//                        fiveDetailItemView.setVisibility(View.VISIBLE);
//                        fiveDetailItemView.setTitle("指定承运人：");
//                        fiveDetailItemView.setContent(data.senttodetails);
//                    } else {
//                        fiveDetailItemView.setVisibility(View.GONE);
//                    }
//                    //询价
//                    sevenDetailItemView.setVisibility(View.VISIBLE);
//                    sevenDetailItemView.setTitle("是否询价：");
//                    if (!TextUtils.isEmpty(data.ishide) && data.ishide.equals("1")) {
//                        sevenDetailItemView.setContent("是" + "（" + data.facetel + "）");
//                    } else {
//                        sevenDetailItemView.setContent("否");
//                    }
//
//                } else {
//                    editOrderTextView.setVisibility(View.GONE);
//                    shareCodeTextView.setVisibility(View.GONE);
//                    goodsDetailLinearLayout.setVisibility(View.GONE);
//                }
//
//            }

        }
    }
}
